#include"progress.h"

#define Length 101 
#define Style '='






void progress(double total,double content)
{
  char bar[Length];
  char Lsign[4]={'|','/','-','\\'};
  memset(bar,'\0',sizeof(bar));
  if(content>total)
    content=total;
  int con=(int)(content*100.0/total);
  int cnt=0;
  while(cnt<con)
  {
    bar[cnt++]=Style;
  }
    printf("[%-100s][%3d%%][%c][%0.3f-%0.3f]\r",bar,cnt,Lsign[con%4],content,total);
    fflush(stdout);
    usleep(100000);
  
}


void download(double total,double speed)
{
  printf("The download is begining,speed:%0.3f\n",speed);
  double content=0.0;
  progress(total,content);
  while(content<=total)
  {
    content+=speed;
    progress(total,content);
  }
  printf("\nThe download complete,volume:%0.3f\n",total);
}


